﻿@*@model IEnumerable<CoreLims.Models.CoreLims.TestDefinition>*@

@{
    ViewBag.Title = "测试管理";
}

<div class="row col-md-12 ml-0" style="min-height:5vh;">
    <strong class="font-rfs" style="margin-right: 2rem;padding-top: 0.4rem;">测试管理</strong>
    <div class="input-group col-3 pl-0">
        <select id="TestDefinition-Select-FirstGroup" class="form-control font-rfs custom-headtoolbar-select"></select>
        <select id="TestDefinition-Select-SecondGroup" class="form-control font-rfs custom-headtoolbar-select"></select>
    </div>
    <button id="TestDefinition-addTestDefinition" class="btn btn-rfs"><i class="bi-plus-square"></i> 添加</button>
    <button id="TestDefinition-EditTestDefinition" class="btn btn-rfs"><i class="bi-pencil-square"></i> 编辑</button>
    <button id="TestDefinition-DeleteTestDefinition" class="btn btn-rfs"><i class="bi-trash" onclick=""></i> 删除</button>
</div>
<div class="row col-md-12 ml-0" style="min-height:90vh;">
    <div class="row col-md-12" style="padding-right:0px;left: 15px;padding-left: 0px;min-height:40vh;">
        <div class="table-responsive-sm shadow p-0 bg-white rounded col-md-12 pre-scrollable" style="min-height:40vh;">
            <table id="TestDefinition-TestDefinitionList" class="table table-striped table-bordered table-sm table-hover">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>名称</th>
                        <th>描述</th>
                        <th>一级分类</th>
                        <th>二级分类</th>
                        <th>版本</th>
                        <th>状态</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>
    </div>
    <div class="row col-md-12 ml-0" style="margin-top: 8px; padding-right:0px;padding-left: 0px;min-height:49vh;">
        <div class="row col-md-12 tab-content" style="padding-left: 0;padding-right: 0px;right: -15px;min-height: 3vh;">
            <ul class="nav col-md-12" style="padding-right: 0;margin-bottom: 1px;">
                <li id="li-tabAnalyte" class="tabButton col-md-1 tab-first-active font-rfs" style="text-align:center;padding-left: 1px;padding-right: 1px;" data-active="true">
                    <a id="a-tabAnalyte" href="#tabAnalyte" data-toggle="tab" class="text-decoration-none" style="display: inline-block;width:100%;">分析项</a>
                </li>
                <li id="li-tabSpecCollection" class="tabButton col-md-1 tab-other-noactive font-rfs" style="text-align: center;padding-left: 1px;padding-right: 1px;" data-active="false">
                    <a id="a-tabSpecCollection" href="#tabSpecCollection" data-toggle="tab" class="text-decoration-none" style="display: inline-block;width:100%;">指标集</a>
                </li>
                <li id="li-tabMethod" class="tabButton col-md-1 tab-other-noactive font-rfs" style="text-align: center;padding-left: 1px;padding-right: 1px;" data-active="false">
                    <a id="a-tabMethod" href="#tabMethod" data-toggle="tab" class="text-decoration-none" style="display: inline-block;width:100%;">方法</a>
                </li>
                <li class="col-md-9 tab-Notactive" style="text-align: center;"><a href="" data-toggle="tab"></a></li>
            </ul>
        </div>
        <div class="row col-md-12 tab-content tab-body" style="padding-right: 0px;right: -15px;padding-left: 0px;top: -2px;">
            <div class="col-md-12 ml-0 mr-0 tab-pane active tab-content" id="tabAnalyte" style="padding-right: 0px;padding-left: 0px;min-height:46vh;">
            <div class="row col-md-12" style="min-height:2vh;">
                <button id="TestDefinition-tabAnalyte-addAnalyte" class="btn btn-rfs"><i class="bi-plus-square"></i> 添加</button>
                <button id="TestDefinition-tabAnalyte-delAnalyte" class="btn btn-rfs"><i class="bi-trash" onclick=""></i> 删除</button>
            </div>
                <div class="table-responsive-sm p-0 bg-white rounded col-md-12 pre-scrollable" style="min-height:41vh;">
                <table id="TestDefinition-Analyte" class="table table-striped table-bordered table-sm table-hover">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>代码</th>
                            <th>名称</th>
                            <th>分类</th>
                            <th>描述</th>
                            <th>结果模式</th>
                            <th>修约</th>
                            <th>单位</th>
                            <th>默认指标名</th>
                            <th>报告过滤</th>
                            <th>检测次数</th>
                            <th>规则</th>
                        </tr>
                    </thead>
                    <tbody></tbody>
                </table>
            </div>
        </div>
        <div class="col-md-12 ml-0 mr-0 tab-pane " id="tabSpecCollection" style="padding-left: 0px;padding-right: 0px;">
            <div class="row col-md-12" style="min-height:2vh;">
                <button id="SampleDefinition-tabSpecCollection-addSpc" class="btn btn-rfs"><i class="bi-plus-square"></i> 添加</button>
                <button id="SampleDefinition-tabSpecCollection-delSpc" class="btn btn-rfs"><i class="bi-trash" onclick=""></i> 删除</button>
            </div>
            <div class="col-md-12 ml-0 mr-0 tab-pane" style="padding-left: 0px;padding-right: 0px;">
                <div class="table-responsive-sm p-0 bg-white rounded col-md-12 pre-scrollable" style="min-height:41vh;">
                    <table id="SpecCollection-SpecList" class="table table-striped table-bordered table-sm table-hover">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>默认</th>
                                <th>代码</th>
                                <th>名称</th>
                                <th>描述</th>
                                <th>一级分类</th>
                                <th>二级分类</th>
                                <th>版本</th>
                                <th>状态</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="col-md-12 ml-0 mr-0 tab-pane " id="tabMethod" style="padding-left: 0px;padding-right: 0px;">
            <div class="row col-md-12" style="min-height:2vh;">
                <button id="SampleDefinition-tabMethod-addM" class="btn btn-rfs"><i class="bi-plus-square"></i> 添加</button>
                <button id="SampleDefinition-tabMethod-delM" class="btn btn-rfs"><i class="bi-trash" onclick=""></i> 删除</button>
            </div>
            <div class="col-md-12 ml-0 mr-0 tab-pane" style="padding-left: 0px;padding-right: 0px;">
                <div class="table-responsive-sm p-0 bg-white rounded col-md-12 pre-scrollable" style="min-height:41vh;">
                    <table id="TestDefinition-Method-Table" class="table table-striped table-bordered table-sm table-hover">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>默认</th>
                                <th>代码</th>
                                <th>名称</th>
                                <th>类型</th>
                                <th>描述</th>
                                <th>生效日期</th>
                                <th>有效期至</th>
                                <th>记录单</th>
                                <th>版本</th>
                                <th>状态</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                </div>
            </div>
        </div>
        </div>
    </div>
</div>
<div class="modal" id="SAMPLE-TestDefinition-Modal" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p id="modalTitle" class="pt-3 pl-3 font-rfs"></p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <div id="Embed"></div>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="DeleteConfirm" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p class="pt-3 pl-3 font-rfs">删除</p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <p class="font-rfs">确认删除当前选中测试吗？</p>
            </div>
            <div class="modal-Delete-footer">
                <button id="modal-delete" class="btn btn-outline-primary border-radius-noradius noLeftBorder noRightBorder font-rfs" style="width:50%; height:fit-content">删除</button>
                <button id="modal-cancel" data-dismiss="modal" class="btn btn-outline-primary border-radius-noradius noRightBorder font-rfs" style="width:50%; height:fit-content">取消</button>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="TestDefinition-delAnalyte-modal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p class="pt-3 pl-3 font-rfs">删除</p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <p class="font-rfs">确认删除当前关联的分析项吗？</p>
                <p id="TestDefinition-delAnalyte-modal-tips" class="font-rfs" style="display:none">注意：当前分析项包含自定义规则，删除后有可能导致当前测试失效！</p>
            </div>
            <div class="modal-Delete-footer">
                <button id="TestDefinition-delAnalyte-modal-delete" class="btn btn-outline-primary border-radius-noradius noLeftBorder noRightBorder font-rfs" style="width:50%; height:fit-content">删除</button>
                <button id="TestDefinition-delAnalyte-modal-cancel" data-dismiss="modal" class="btn btn-outline-primary border-radius-noradius noRightBorder font-rfs" style="width:50%; height:fit-content">取消</button>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="TestDefinition-delSpecCollection-modal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p class="pt-3 pl-3 font-rfs">删除</p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <p class="font-rfs">确认删除当前关联的指标集吗？</p>
            </div>
            <div class="modal-Delete-footer">
                <button id="TestDefinition-delSpecCollection-modal-delete" class="btn btn-outline-primary border-radius-noradius noLeftBorder noRightBorder font-rfs" style="width:50%; height:fit-content">删除</button>
                <button id="TestDefinition-delSpecCollection-modal-cancel" data-dismiss="modal" class="btn btn-outline-primary border-radius-noradius noRightBorder font-rfs" style="width:50%; height:fit-content">取消</button>
            </div>
        </div>
    </div>
</div>
<div class="modal" id="TestDefinition-delMethod-modal" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class='modal-header'>
                <p class="pt-3 pl-3 font-rfs">删除</p>
                <a data-dismiss="modal" class="modal-close">&times;</a>
            </div>
            <div class="modal-body">
                <p class="font-rfs">确认删除当前关联的方法吗？</p>
            </div>
            <div class="modal-Delete-footer">
                <button id="TestDefinition-delMethod-modal-delete" class="btn btn-outline-primary border-radius-noradius noLeftBorder noRightBorder font-rfs" style="width:50%; height:fit-content">删除</button>
                <button id="TestDefinition-delMethod-modal-cancel" data-dismiss="modal" class="btn btn-outline-primary border-radius-noradius noRightBorder font-rfs" style="width:50%; height:fit-content">取消</button>
            </div>
        </div>
    </div>
</div>

@section Scripts{
    <script>
        var TestDefinition_TestDefinitionId = "";
        var TestDefinition_TestAnalyteId = "";
        var TestDefinition_SpecCollectionId = "";
        var TestDefinition_MethodId = "";

        /*页面加载时，加载 一级分类 信息*/
        $.post("GetTestDefinitionFirstGroup", {
            //Type: type  // 传递的参数，对应控制器里的参数
        }, function (data) {
            for (var i = 0; i < data.length; i++) {
                $("#TestDefinition-Select-FirstGroup").append(new Option(data[i].firstGroup));
            }
            $("#TestDefinition-Select-FirstGroup").prepend(new Option("全部"));
            $("#TestDefinition-Select-FirstGroup").prepend(new Option("", ""));
            $("#TestDefinition-Select-FirstGroup").val("");
        });

        $("#TestDefinition-Select-FirstGroup").change(function () {
            $.post("GetTestDefinitionSecondGroup", { /* 加载 二级分类 信息*/
                FirstGroup: $("#TestDefinition-Select-FirstGroup").find("option:selected").text()  // 传递的参数，对应控制器里的参数
            }, function (data) {
                $("#TestDefinition-Select-SecondGroup").empty();
                for (var i = 0; i < data.length; i++) {
                    $("#TestDefinition-Select-SecondGroup").append(new Option(data[i].secondGroup));
                }
                $("#TestDefinition-Select-SecondGroup").prepend(new Option("", ""));
                $("#TestDefinition-Select-SecondGroup").val("");

                RefreshTestDefinitionTable();
            });
        });

        $("#TestDefinition-Select-SecondGroup").change(function () {
            RefreshTestDefinitionTable();
        });

        function SetTestDefinitionEnableCortrol(value, row, index) { // 启用禁用该功能还未完善
            var strHtml = "";
            if(row.enable) {
                strHtml = "<input type='checkbox' checked data-rowid='" + row.id + "'/>";
            } else {
                strHtml = "<input type='checkbox' data-rowid='" + row.id + "'/>";
            }
                               
            return strHtml;
        }

        function RefreshTestDefinitionTable() {
            TestDefinition_TestDefinitionId = "";  /*清空该值*/
            $('#TestDefinition-TestDefinitionList').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
            var columns = [{ field: "id", visible: false }, { field: "testName"}, { field: "description"},
            { field: "firstGroup" }, { field: "secondGroup" },
            { field: "version", width:"5%", align:"center" },
            { field: "releaseStatus", width: "5%", align: "center" }];

            $('#TestDefinition-TestDefinitionList').bootstrapTable({
                method: 'post',
                url: "GetTestDefinitionListFirstAndBySecond",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                queryParams: function (params) {
                    var data = {
                        FirstGroup: $("#TestDefinition-Select-FirstGroup").find("option:selected").text(),  // 传递的参数，这的名称要和控制器里对应的参数名称一样
                        SecondGroup: $("#TestDefinition-Select-SecondGroup").find("option:selected").text()
                    };
                    return data;
                }, //参数
                queryParamsType: "search", //参数格式,发送标准的RESTFul类型的参数请求

                uniqueId: "id",          // 设置主键
                //search: true,  // 显示查询工具栏
                //showRefresh: true,  // 显示刷新按钮
                //showColumns: true,  // 可控制列的隐藏和显示
                pagination: true,  // 显示分页条,设为true，启用了分页功能
                pageSize: 15,   // 默认页大小
                pageList: [5, 10, 15, 20],  // 控制每页数目
                //showToggle: true,  //
                locale: "zh-CN",
                columns: columns,          // 加载列定义, 注意！这个地方绑定的列名称开头大写字母会全部变成小写。
                onClickRow: function (row, $element, field) {
                    $("#TestDefinition-TestDefinitionList").find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                    TestDefinition_TestDefinitionId = row.id;
                    LoadAnalyte(TestDefinition_TestDefinitionId);
                    LoadSpecCollection(TestDefinition_TestDefinitionId);
                    LoadMethod(TestDefinition_TestDefinitionId);
                },
                silent: true,  //刷新事件必须设置
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#TestDefinition-TestDefinitionList').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
        }

        function SetCalculationRulesButton(value, row, index) {
            var strHtml = "<button class='table-cell-button btn-rfs' data-Id=" + row.id + "  title='自定义计算规则' onclick='CalculationRulesButtenClick(this)'><i class='bi-file-code'></i></button>";
            return strHtml;
        }

        function CalculationRulesButtenClick(obj) {
            $("#modalTitle").text("计算规则");

            $("#SAMPLE-TestDefinition-Modal").modal({
                backdrop: 'static',
                keyboard: false
            });

            $.post("TestAnalyteCalculationRules", {
                TestRelationId: $(obj.outerHTML).attr("data-Id"),
                ModalID: "SAMPLE-TestDefinition-Modal"
            }, function (data) {
                $("#Embed").html(data);
            });
        }

        function SetDetectionTimes(value, row, index) {
            var text = value == null ? '-' : value;
            var strHtml = "<input class='table-cell-input' data-Id=" + row.id + "  onchange='UpdateDetectionTimes(this)' value='" + text + "'/>";
            return strHtml;
        }

        function UpdateDetectionTimes(obj) {
            var st = $(obj).val();
            $.post("postUpdateTestRelationDetectionTimes", {
                Id: $(obj.outerHTML).attr("data-Id"),
                times: st
            },  function (data) {
                if (data.indexOf("成功") <= 0) {
                    alert(data);
                }
            });
        }

        function LoadAnalyte(TestDefinitionId) {
            TestDefinition_TestAnalyteId = "";
            var columns = [{ field: "id", visible: false },{ field: "code" }, { field: "name" }, { field: "classification" }, { field: "description"}, 
            { field: "resultModel" },{ field: "roundingOff" }, { field: "units" }, { field: "defaultSpecName" }, { field: "assist" },
            { field: "detectionTimes", width: "5%", formatter: SetDetectionTimes },
            { field: "calculationRules", width: "5%", formatter: SetCalculationRulesButton }];

            $('#TestDefinition-Analyte').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
            $('#TestDefinition-Analyte').bootstrapTable({
                method: 'post',
                url: "GetTestDefinitionRelationAnalytes",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                queryParams: function (params) {
                    var data = {
                        TestDefinitionId: TestDefinition_TestDefinitionId,  // 传递的参数，这的名称要和控制器里对应的参数名称一样
                    };
                    return data;
                }, //参数
                queryParamsType: "search", //参数格式,发送标准的RESTFul类型的参数请求

                uniqueId: "id",          // 设置主键
                //search: true,  // 显示查询工具栏
                //showRefresh: true,  // 显示刷新按钮
                //showColumns: true,  // 可控制列的隐藏和显示
                //pagination: true,  // 显示分页条,设为true，启用了分页功能  暂时不分页
                //pageSize: 15,   // 默认页大小
                //pageList: [5, 10, 15, 20],  // 控制每页数目
                //showToggle: true,  //
                locale: "zh-CN",
                columns: columns,          // 加载列定义, 注意！这个地方绑定的列名称开头大写字母会全部变成小写。
                onClickRow: function (row, $element, field) {
                    $("#TestDefinition-Analyte").find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                    TestDefinition_TestAnalyteId = row.id;
                },
                silent: true,  //刷新事件必须设置
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#Analyte').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
            
        }

        function SetSpecCollectionIsDefault(value, row, index) {
            var strHtml = "";
            if (row.isDefault) {
                strHtml = "<input type='checkbox' checked onclick='UpdateSpecCollectionIsDefault(this)' data-rowid='" + row.id + "'/>";
            } else {
                strHtml = "<input type='checkbox' onclick='UpdateSpecCollectionIsDefault(this)' data-rowid='" + row.id + "'/>";
            }
            return strHtml;
        }

        function UpdateSpecCollectionIsDefault(obj) {
            var rowid = $(obj).attr("data-rowid");

            $.post("SetSpecCollectionIsDefault", {
                Id: rowid
            }, function (data) {
                if (data.indexOf("成功") >= 0) {
                    LoadSpecCollection(TestDefinition_TestDefinitionId);
                } else {
                    alert(data);
                }
            });
        }

        function InitSubTable(index, row, $detail) {
            var subtable = $detail.html('<table></table>').find('table');
            var columns = [{ field: "id", visible: false }, { field: "code", title:"代码" }, { field: "name", title:"名称" }, 
            { field: "classification", title:"分类" }, { field: "description", title:"描述" },{ field: "resultModel", title: "结果模式" },
            { field: "roundingOff", title: "修约" }, { field: "units", title: "单位" }, { field: "lowA", title: "lowA" },
            { field: "lowB", title: "lowB" }, { field: "highB", title: "highB" }, { field: "highA", title: "highA" }, 
            { field: "acceptanceCriteria", title:"验收标准" }];
            
            $(subtable).bootstrapTable({
                method: 'post',
                url: "GetSpecCollectionAnalytesByTestRelationId",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                queryParams: function (params) {
                    var data = {
                        TestRelationId: row.id,  // 传递的参数，这的名称要和控制器里对应的参数名称一样
                    };
                    return data;
                }, //参数
                queryParamsType: "search", //参数格式,发送标准的RESTFul类型的参数请求

                uniqueId: "id",          // 设置主键
                locale: "zh-CN",
                columns: columns,          // 加载列定义, 注意！这个地方绑定的列名称开头大写字母会全部变成小写。
                onClickRow: function (row, $element, field) {
                    $(subtable).find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                },
                silent: true,  //刷新事件必须设置
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $(subtable).bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
        }

        function LoadSpecCollection(TestDefinitionId) {
            TestDefinition_SpecCollectionId = "";
            var columns = [{ field: "id", visible: false }, { field: "isDefault", width: "5%", align: "center", formatter: SetSpecCollectionIsDefault },
            { field: "code" }, { field: "name" }, { field: "description" },
            { field: "firstGroup" }, { field: "secondGroup" },{ field: "version" }, { field: "releaseStatus" }];

            $('#SpecCollection-SpecList').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
            $('#SpecCollection-SpecList').bootstrapTable({
                method: 'post',
                url: "GetTestDefinitionRelationSpecCollection",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                queryParams: function (params) {
                    var data = {
                        TestDefinitionId: TestDefinition_TestDefinitionId,  // 传递的参数，这的名称要和控制器里对应的参数名称一样
                    };
                    return data;
                }, //参数
                queryParamsType: "search", //参数格式,发送标准的RESTFul类型的参数请求

                uniqueId: "id",          // 设置主键
                locale: "zh-CN",
                columns: columns,          // 加载列定义, 注意！这个地方绑定的列名称开头大写字母会全部变成小写。
                onClickRow: function (row, $element, field) {
                    $("#SpecCollection-SpecList").find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                    TestDefinition_SpecCollectionId = row.id;
                },
                silent: true,  //刷新事件必须设置

                detailView: true,  // 详细视图必须设置该项
                icons:{  // 设置详细视图的图标
                    detailOpen: 'bi-plus',
                    detailClose: 'bi-dash'
                },
                onExpandRow: function (index, row, $detail) {  // 单击展开视图时触发的函数
                     InitSubTable(index, row, $detail);
                },

                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#Analyte').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
        }

        function SetMethodIsDefault(value, row, index) {
            var strHtml = "";
            if (row.isDefault) {
                strHtml = "<input type='checkbox' checked onclick='UpdateMethodIsDefault(this)' data-rowid='" + row.id + "'/>";
            } else {
                strHtml = "<input type='checkbox' onclick='UpdateMethodIsDefault(this)' data-rowid='" + row.id + "'/>";
            }
            return strHtml;
        }

        function UpdateMethodIsDefault(obj) {
            var rowid = $(obj).attr("data-rowid");
            $.post("SetMethodIsDefault", {
                Id: rowid
            }, function (data) {
                if (data.indexOf("成功") >= 0) {
                    LoadMethod(TestDefinition_TestDefinitionId);
                } else {
                    alert(data);
                }
            });

        }

        function setEffectiveDate(value, row, index) {
            if (!row.effectiveDate) {
                return '';
            } else {
                return row.effectiveDate.split('T')[0];
            }
        }

        function setExpireDate(value, row, index) {
            if (!row.expireDate) {
                return '';
            } else {
                return row.expireDate.split('T')[0];
            }
        }

        function LoadMethod(testDefinitionId) {
            TestDefinition_MethodId = "";
            var columns = [{ field: "id", visible: false }, { field: "isDefault", width: "5%", align: "center", formatter: SetMethodIsDefault },
            { field: "code" }, { field: "name" }, { field: "type" }, { field: "description" },
            { field: "effectiveDate", formatter: setEffectiveDate }, { field: "expireDate", formatter: setExpireDate }, { field: "recordSheet" },
            { field: "version", width: "5%", },{ field: "status", width: "5%", }];

            $('#TestDefinition-Method-Table').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
            $('#TestDefinition-Method-Table').bootstrapTable({
                method: 'post',
                url: "GetTestDefinitionRelationMethod",
                dataType: "json",  // 服务器端返回值类型
                contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
                queryParams: function (params) {
                    var data = {
                        TestDefinitionId: testDefinitionId,  // 传递的参数，这的名称要和控制器里对应的参数名称一样
                    };
                    return data;
                }, //参数
                queryParamsType: "search", //参数格式,发送标准的RESTFul类型的参数请求

                uniqueId: "id",          // 设置主键
                locale: "zh-CN",
                columns: columns,          // 加载列定义, 注意！这个地方绑定的列名称开头大写字母会全部变成小写。
                onClickRow: function (row, $element, field) {
                    $("#TestDefinition-Method-Table").find("tbody").find("tr").each(function () {
                        $(this).removeClass('changeblueColor');
                    });
                    $element.addClass("changeblueColor");
                    TestDefinition_MethodId = row.id;
                },
                silent: true,  //刷新事件必须设置
                formatLoadingMessage: function () {
                    return "请稍等，正在加载中...";
                },
                formatNoMatches: function () {  //没有匹配的结果
                    return '无符合条件的记录';
                },
                onLoadError: function (data) {
                    $('#TestDefinition-Method-Table').bootstrapTable('removeAll');
                },
                onLoadSuccess: function (data) {   // 数据加载成功后触发该事件
                    SetBootstrapStyle();
                },
                formatShowingRows: function (pageFrom, pageTo, totalRows) {
                    return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
                },
                formatRecordsPerPage: function (pageNumber) {
                    return " 每页显示" + pageNumber + '条记录';
                }
            });
        }

        $("#TestDefinition-DeleteTestDefinition").click(function () {
            if (TestDefinition_TestDefinitionId == "") {
                return false;
            }

            $("#DeleteConfirm").modal({
                backdrop: 'static',
                keyboard: false
            });
        });

        $("#modal-delete").click(function () {
            $.post("postDeleteTestDefinition", {
                Id: TestDefinition_TestDefinitionId
            }, function (data) {
                if (data == "删除成功！") {
                    $('#TestDefinition-TestDefinitionList').bootstrapTable('removeByUniqueId', TestDefinition_TestDefinitionId);  // 删除指定的行
                    TestDefinition_TestDefinitionId = "";  // 删除行后，将这个值置空，否则直接编辑信息就会报错。
                    $('#TestDefinition-Analyte').bootstrapTable('removeAll');
                    $('#SpecCollection-SpecList').bootstrapTable('removeAll');
                    $('#TestDefinition-Method-Table').bootstrapTable('removeAll');

                } else {
                    alert(data);
                }
            });

            $("#DeleteConfirm").modal('hide');
        });

        $("#TestDefinition-delAnalyte-modal-delete").click(function () {

            $.post("DelteRelationTestDefinitionAndAanylte", {
                TestRelationID: TestDefinition_TestAnalyteId
            }, function (data) {
                $('#TestDefinition-Analyte').bootstrapTable('removeByUniqueId', TestDefinition_TestAnalyteId);  // 删除指定的行
                TestDefinition_TestAnalyteId = "";  // 删除行后，将这个值置空，否则再次删除就会报错。
            });

            $("#TestDefinition-delAnalyte-modal").modal('hide');
        });

        $("#TestDefinition-delSpecCollection-modal-delete").click(function () {

            $.post("DelteRelationTestDefinitionAndAanylte", {
                TestRelationID: TestDefinition_SpecCollectionId
            }, function (data) {
                LoadSpecCollection(TestDefinition_TestDefinitionId);
                TestDefinition_SpecCollectionId = "";  // 删除行后，将这个值置空，否则再次删除就会报错。
            });

            $("#TestDefinition-delSpecCollection-modal").modal('hide');
        });

        $("#TestDefinition-delMethod-modal-delete").click(function () {

            $.post("DelteRelationTestDefinitionAndAanylte", {
                TestRelationID: TestDefinition_MethodId
            }, function (data) {
                LoadMethod(TestDefinition_TestDefinitionId);
                TestDefinition_MethodId = "";  // 删除行后，将这个值置空，否则再次删除就会报错。
            });

            $("#TestDefinition-delMethod-modal").modal('hide');
        });

        $("#TestDefinition-addTestDefinition").click(function () {
            $("#modalTitle").text("新建测试");

            $("#SAMPLE-TestDefinition-Modal").modal({
                backdrop: 'static',
                keyboard: false
            });

            $.post("AddTestDefinition", {
                ModalID: "SAMPLE-TestDefinition-Modal"
            }, function (datas) {
                $("#Embed").html(datas);
            });
        });

        $("#TestDefinition-EditTestDefinition").click(function () {
            if (TestDefinition_TestDefinitionId.length == 0) {
                alert("请先选择需要编辑的测试！");
                return;
            }

            $("#modalTitle").text("编辑测试");

            $("#SAMPLE-TestDefinition-Modal").modal({
                backdrop: 'static',
                keyboard: false
            });

            $.post("AddTestDefinition", {
                Id: TestDefinition_TestDefinitionId,
                ModalID: "SAMPLE-TestDefinition-Modal"
            }, function (datas) {
                $("#Embed").html(datas);
            });
        });

        $('#SAMPLE-TestDefinition-Modal').on('hidden.bs.modal', function (event) {
            if (event.target == this) {
                if (TestDefinition_TestDefinitionId.length > 0) {
                    $.post("GetTestDefinition", {
                        Id: TestDefinition_TestDefinitionId
                    }, function (data) {
                        var row = $('#TestDefinition-TestDefinitionList').bootstrapTable('getRowByUniqueId', TestDefinition_TestDefinitionId);
                        row.testName = data.testName;
                        row.description = data.description;
                        row.firstGroup = data.firstGroup;
                        row.secondGroup = data.secondGroup;
                        $('#TestDefinition-TestDefinitionList').bootstrapTable('updateByUniqueId',row);

                        LoadAnalyte(TestDefinition_TestDefinitionId);
                        LoadSpecCollection(TestDefinition_TestDefinitionId);
                        LoadMethod(TestDefinition_TestDefinitionId);

                        $("#TestDefinition-TestDefinitionList").find("tbody").find("tr").each(function () {
                            if ($(this).attr("data-uniqueid") == TestDefinition_TestDefinitionId)
                                $(this).addClass("changeblueColor");
                        });
                    });
                }
            }
        });

        $("#TestDefinition-tabAnalyte-addAnalyte").click(function () {
            if (TestDefinition_TestDefinitionId.length == 0) {
                alert("请先选择需要添加关系的测试！");
                return;
            }

            $("#modalTitle").text("添加关联分析项");

            $("#SAMPLE-TestDefinition-Modal").modal({
                backdrop: 'static',
                keyboard: false
            });
            
            $.post("AddSpecRelationAnalyte", {
                Relation:"TestDefinition",
                Id :TestDefinition_TestDefinitionId,
                ModalID: "SAMPLE-TestDefinition-Modal"
            }, function (datas) {
                $("#Embed").html(datas);
            });
        });

        $("#TestDefinition-tabAnalyte-delAnalyte").click(function () {
            if (TestDefinition_TestAnalyteId.length == 0) {
                alert("请先选择需要删除关系的分析项！");
                return;
            }

            $("#modalTitle").text("删除关联分析项");

            $.post("CheckHasCalculationRules", {
                TestRelationId: TestDefinition_TestAnalyteId,
            }, function (data) {
                if (data.indexOf("true") >= 0) {
                    $("#TestDefinition-delAnalyte-modal-tips").css('display', 'block');
                }
            });

            $("#TestDefinition-delAnalyte-modal").modal({
                backdrop: 'static',
                keyboard: false
            });
        });

        $("#SampleDefinition-tabSpecCollection-delSpc").click(function () {
            if (TestDefinition_SpecCollectionId.length == 0) {
                alert("请先选择需要删除关系的指标集！");
                return;
            }

            $("#modalTitle").text("删除关联指标集");

            $("#TestDefinition-delSpecCollection-modal").modal({
                backdrop: 'static',
                keyboard: false
            });
        });

        $("#SampleDefinition-tabMethod-delM").click(function () {
            if (TestDefinition_MethodId.length == 0) {
                alert("请先选择需要删除关系的方法！");
                return;
            }

            $("#modalTitle").text("删除关联方法");

            $("#TestDefinition-delMethod-modal").modal({
                backdrop: 'static',
                keyboard: false
            });
        });

        $("#SampleDefinition-tabSpecCollection-addSpc").click(function () {
            if (TestDefinition_TestDefinitionId.length == 0) {
                alert("请先选择需要添加关系的测试！");
                return;
            }

            $("#modalTitle").text("添加关联指标集");

            $("#SAMPLE-TestDefinition-Modal").modal({
                backdrop: 'static',
                keyboard: false
            });

            $.post("AddTestSpecCollection", {
                TestDefinitionId: TestDefinition_TestDefinitionId,
                ModalID: "SAMPLE-TestDefinition-Modal"
            }, function (datas) {
                $("#Embed").html(datas);
            });
        });

        $("#SampleDefinition-tabMethod-addM").click(function () {
            if (TestDefinition_TestDefinitionId.length == 0) {
                alert("请先选择需要添加关系的测试！");
                return;
            }

            $("#modalTitle").text("添加关联方法");

            $("#SAMPLE-TestDefinition-Modal").modal({
                backdrop: 'static',
                keyboard: false
            });

            $.post("AddTestMethod", {
                TestDefinitionId: TestDefinition_TestDefinitionId,
                ModalID: "SAMPLE-TestDefinition-Modal"
            }, function (datas) {
                $("#Embed").html(datas);
            });
        });

        $("#li-tabAnalyte").hover(
            function () {
                if ($(this).attr("class").indexOf('tab-first-active') > 0) {
                    $(this).addClass('tab-enter-mouse');
                }
                if ($(this).attr("class").indexOf('tab-first-noactive') > 0) {
                    $(this).removeClass('tab-first-noactive');
                    $(this).addClass('tab-first-noactive-mouse');
                }
            },
            function () {
                $(this).removeClass('tab-enter-mouse');
                $(this).removeClass('tab-first-noactive-mouse');

                if ($(this).attr("data-active") == 'true') {
                    $(this).addClass('tab-first-active');
                }
                if ($(this).attr("data-active") == 'false') {
                    $(this).addClass('tab-first-noactive');
                }
            });

        $("#li-tabSpecCollection").hover(
            function () {
                if ($(this).attr("class").indexOf('tab-other-active') > 0) {
                    $(this).addClass('tab-enter-mouse');
                }
                if ($(this).attr("class").indexOf('tab-other-noactive') > 0) {
                    $(this).removeClass('tab-other-noactive');
                    $(this).addClass('tab-other-noactive-mouse');
                }
            },
            function () {
                $(this).removeClass('tab-enter-mouse');
                $(this).removeClass('tab-other-noactive-mouse');

                if ($(this).attr("data-active") == 'true') {
                    $(this).addClass('tab-other-active');
                }
                if ($(this).attr("data-active") == 'false') {
                    $(this).addClass('tab-other-noactive');
                }
            });

        $("#li-tabMethod").hover(
            function () {
                if ($(this).attr("class").indexOf('tab-other-active') > 0) {
                    $(this).addClass('tab-enter-mouse');
                }
                if ($(this).attr("class").indexOf('tab-other-noactive') > 0) {
                    $(this).removeClass('tab-other-noactive');
                    $(this).addClass('tab-other-noactive-mouse');
                }
            },
            function () {
                $(this).removeClass('tab-enter-mouse');
                $(this).removeClass('tab-other-noactive-mouse');

                if ($(this).attr("data-active") == 'true') {
                    $(this).addClass('tab-other-active');
                }
                if ($(this).attr("data-active") == 'false') {
                    $(this).addClass('tab-other-noactive');
                }
            });

        $("#a-tabAnalyte").click(function () {
            if($("#li-tabSpecCollection").attr("class").indexOf('tab-other-active') > 0){
                $("#li-tabSpecCollection").removeClass('tab-other-active');
                $("#li-tabSpecCollection").addClass('tab-other-noactive');
            }
            if($("#li-tabMethod").attr("class").indexOf('tab-other-active') > 0){
                $("#li-tabMethod").removeClass('tab-other-active');
                $("#li-tabMethod").addClass('tab-other-noactive');
            }

            $("#li-tabAnalyte").attr("data-active", true);
            $("#li-tabSpecCollection").attr("data-active", false);
            $("#li-tabMethod").attr("data-active", false);
        });

        $("#a-tabSpecCollection").click(function () {
            if($("#li-tabAnalyte").attr("class").indexOf('tab-first-active') > 0){
                $("#li-tabAnalyte").removeClass('tab-first-active');
                $("#li-tabAnalyte").addClass('tab-first-noactive');
            }
            if($("#li-tabMethod").attr("class").indexOf('tab-other-active') > 0){
                $("#li-tabMethod").removeClass('tab-other-active');
                $("#li-tabMethod").addClass('tab-other-noactive');
            }

            $("#li-tabAnalyte").attr("data-active", false);
            $("#li-tabSpecCollection").attr("data-active", true);
            $("#li-tabMethod").attr("data-active", false);
        });

        $("#a-tabMethod").click(function () {
            if($("#li-tabAnalyte").attr("class").indexOf('tab-first-active') > 0){
                $("#li-tabAnalyte").removeClass('tab-first-active');
                $("#li-tabAnalyte").addClass('tab-first-noactive');
            }
            if($("#li-tabSpecCollection").attr("class").indexOf('tab-other-active') > 0){
                $("#li-tabSpecCollection").removeClass('tab-other-active');
                $("#li-tabSpecCollection").addClass('tab-other-noactive');
            }

            $("#li-tabAnalyte").attr("data-active", false);
            $("#li-tabSpecCollection").attr("data-active", false);
            $("#li-tabMethod").attr("data-active", true);
        });

    </script>
}
